package com.uniapp.server.service.impl;

import com.uniapp.server.config.exceptionhandler.MyException;
import com.uniapp.server.model.UserEntity;
import com.uniapp.server.repository.UserRepository;
import com.uniapp.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author cyt
 * @describe
 * @create 2021-01-17 18:55
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserRepository userRepository;

    @Override
    public void loadUserByName(String username) {
        UserEntity byUsername = userRepository.findByUsername(username);
        if (byUsername == null) {
            throw new MyException(401, "认证失败");
        }
    }

    @Override
    public boolean login(String username) {
        UserEntity u = userRepository.findByUsername(username);
        return u != null;
    }

    @Override
    public UserEntity getUserInfo(String username) {
        return userRepository.findByUsername(username);
    }
}
